package b3.widget.store
{
	import b3.config.*;
	import b3.net.*;
	import b3.widget.basic.*;
	import b3.widget.tab.*;
	
	import flash.text.*;

	public class SpecialZone extends Tab
	{
		public function SpecialZone()
		{
			super("特价区", 3, 2);
			var TabPageFirstPage:Class = ResourceHelper.getInstance().getClassByName("TabPageFirstPage3");
			var TabPagePageUp:Class = ResourceHelper.getInstance().getClassByName("TabPagePageUp3");
			var TabPagePageDown:Class = ResourceHelper.getInstance().getClassByName("TabPagePageDown3");
			var TabPageLastPage:Class = ResourceHelper.getInstance().getClassByName("TabPageLastPage3");
			setPageSelectorStyle(TabPageFirstPage, TabPagePageUp, TabPagePageDown, TabPageLastPage, 0x66FF, 0x66FF);
			setPageSelectorPos(265, 248);
			//特价标语
			var textFormat:TextFormat = new TextFormat("微软雅黑", 15, 0x005500, true);
			textFormat.letterSpacing = 1.2;
			var topMessage:AutoScrollPane = new AutoScrollPane(360);
			//标语1
			var topTitleText:TextField = new TextField();
			topTitleText.selectable = false;
			topTitleText.autoSize = TextFieldAutoSize.LEFT;
			topTitleText.defaultTextFormat = textFormat;
			topTitleText.htmlText = "只在<font color='#FF0000' size='16'><i> 今日 </i></font>哦！过了这个村就没有这个店喽~";
			topMessage.addItem(topTitleText);
			//标语2
			var mostSpecialIndex:int = getMostSpecial();
			if (mostSpecialIndex > 0)
			{
				var objectConfig:ObjConfig = Config.objConfigs[mostSpecialIndex];
				topTitleText = new TextField();
				topTitleText.selectable = false;
				topTitleText.autoSize = TextFieldAutoSize.LEFT;
				topTitleText.defaultTextFormat = textFormat;
				var discountPrice:int = objectConfig.priceGoldIngot * (100 - objectConfig.discount) / 100;
				topTitleText.htmlText = "今日最特价：<font color='#0000FF' size='16'>" + objectConfig.name + "</font>, " + 
							"立减<font color='#FF0000' size='18'><i> " + discountPrice + " </i></font>！";
				topMessage.addItem(topTitleText);
			}
			//标语3
			topTitleText = new TextField();
			topTitleText.selectable = false;
			topTitleText.autoSize = TextFieldAutoSize.LEFT;
			topTitleText.defaultTextFormat = textFormat;
			var objectNames:String = "";
			for (var indexStr:String in Config.objConfigs)
			{
				objectConfig = Config.objConfigs[indexStr];
				var discountStr:String = objectConfig.discount % 10 > 0 ? (objectConfig.discount / 10).toFixed(1) : 
					(objectConfig.discount / 10).toFixed(0);   
				if (objectConfig.discount > 0)
					objectNames += (objectNames.length > 0 ? "、" : "") + "<font color='#0000FF' size='16'>" + 
						objectConfig.name + "</font><font color='#FF0000' size='16'><i> " + discountStr + " </i></font>折";
			}
			topTitleText.htmlText = "所有特价: " + objectNames;  
			topMessage.addItem(topTitleText);
			topMessage.x = 0;
			topMessage.y = -35;
			addChild(topMessage);
		}
		
		private function getMostSpecial():int
		{
			var mostSpecialIndex:int = -1;
			var discountPrice:int = 0;
			for (var indexStr:String in Config.objConfigs)
			{
				var objectConfig:ObjConfig = Config.objConfigs[indexStr];
				if (objectConfig.discount > 0 && objectConfig.priceGoldIngot * (100 - objectConfig.discount) / 100 > discountPrice)
				{
					mostSpecialIndex = parseInt(indexStr);
					discountPrice = objectConfig.priceGoldIngot * (100 - objectConfig.discount) / 100;
				}
			}
			return mostSpecialIndex;
		}
		
	}
}